package com.jfinal.aceadmin.model;
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.jfinal.aceadmin.util.VoUtil;
import com.jfinal.aceadmin.vo.NotificationVo;
@Repository
public class UserNotificationImpl{
	private static ApplicationContext ctx;
	
	public static UserNotificationImpl getDAO() {
		if (null == ctx) {
			ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		}
		UserNotificationImpl instance =  ctx.getBean(UserNotificationImpl.class);
		return instance;
	}

	/**
	 * Get user notifications
	 * @param userId
	 * @return
	 */
	public List<NotificationVo> getNotifications(int userId) {
		List<UserNotification> uNotifications = UserNotification.dao.findByUserIdAndRead(userId, false);
		List<NotificationVo> notificationVos = new ArrayList<NotificationVo>();
		for(UserNotification uNotification : uNotifications){
			NotificationVo notificationVo = VoUtil.convert(uNotification);
			notificationVos.add(notificationVo);
		}
		return notificationVos;
	}
}